<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ListView (GUI)</title>
<meta name="description" content="Create ListView controls easily with this free scripting language. Includes context menus, row/column icons, and click-to-sort column headings.">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>

<body>
<h1>ListView</h1>

<h2>Table of Contents</h2>
<ul>
  <li><a href="#Intro">Introduction and Simple Example</a></li>
  <li><a href="#Options">Options and Styles</a></li>
  <li><a href="#View">View Modes</a>: Report (default), Icon, Tile, Small-Icon, and List.</li>
  <li><a href="#BuiltIn">Built-in Functions</a>:
    <ul>
      <li><a href="#bifRow">Row functions (adding, modifying, and deleting rows)</a></li>
      <li><a href="#bifCol">Column functions</a></li>
      <li><a href="#bifGet">Getting data out of a ListView</a></li>
    </ul>
  </li>
  <li><a href="#notify">G-Label Notifications</a></li>
  <li><a href="#IL">ImageLists</a> (the means by which icons are added to a ListView)</li>
  <li><a href="#Remarks">ListView Remarks</a></li>
  <li><a href="#Examples">Examples</a></li>
</ul>
<h2 id="Intro">Introduction and Simple Example</h2>
<p>A List-View is one of the most elaborate controls provided by the operating system. In its most recognizable form, it displays a tabular view of rows and columns, the most common example of which is Explorer's list of files and folders (detail view).</p>
<p>Though it may be elaborate, a ListView's basic features are easy to use. The syntax for creating a ListView is:</p>
<pre class="Syntax"><a name="GuiAdd"></a>Gui, Add, ListView, Options, ColumnTitle1|ColumnTitle2|...</pre>
<p>Here is a working script that creates and displays a ListView containing a list of files in the user's &quot;My Documents&quot; folder:</p>
<pre><em>; Create the ListView with two columns, Name and Size:</em>
Gui, Add, ListView, r20 w700 gMyListView, Name|Size (KB)

<em>; Gather a list of file names from a folder and put them into the ListView:</em>
Loop, %A_MyDocuments%\*.*
    <a href="#LV_Add">LV_Add</a>(&quot;&quot;, A_LoopFileName, A_LoopFileSizeKB)

<a href="#LV_ModifyCol">LV_ModifyCol</a>()  <em>; Auto-size each column to fit its contents.</em>
LV_ModifyCol(2, &quot;Integer&quot;)  <em>; For sorting purposes, indicate that column 2 is an integer.</em>

<em>; Display the window and return. The script will be notified whenever the user double clicks a row.</em>
Gui, Show
return

MyListView:
if A_GuiEvent = DoubleClick
{
    <a href="#LV_GetText">LV_GetText</a>(RowText, A_EventInfo)  <em>; Get the text from the row's first field.</em>
    ToolTip You double-clicked row number %A_EventInfo%. Text: &quot;%RowText%&quot;
}
return

GuiClose:  <em>; Indicate that the script should exit automatically when the window is closed.</em>
ExitApp</pre>
<h2 id="Options">Options and Styles for &quot;<em>Gui, Add, ListView, <u>Options</u></em>&quot;</h2>
<p><strong><a name="AltSubmit"></a>AltSubmit:</strong> Notifies the script for more types of ListView events than normal. In other words, the g-label is launched more often. See <a href="#notify">ListView Notifications</a> for details.</p>
<p><strong>Background:</strong> Specify the word Background followed immediately by a color name (see <a href="Progress.htm#colors">color chart</a>) or RGB value (the 0x prefix is optional). Examples: <code>BackgroundSilver</code>, <code>BackgroundFFDD99</code>. If this option is not present, the ListView initially defaults to the background color set by the last parameter of <a href="Gui.htm#Color">Gui Color</a> (or if none, the system's default background color). Specifying <code>BackgroundDefault</code> applies the system's default background color (usually white). For example, a ListView can be restored to the default color via <code>GuiControl, +BackgroundDefault, MyListView</code>.</p>
<p><strong>C</strong>: Text color. Specify the letter C followed immediately by a color name (see <a href="Progress.htm#colors">color chart</a>) or RGB value (the 0x prefix is optional). Examples: <code>cRed</code>, <code>cFF2211</code>, <code>c0xFF2211</code>, <code>cDefault</code>.</p>
<p><strong><a name="Checked"></a>Checked:</strong> Provides a checkbox at the left side of each row. When <a href="#LV_Add">adding</a> a row, specify the word <em>Check</em> in its options to have the box to start off checked instead of unchecked. The user may either click the checkbox or press the spacebar to check or uncheck a row.</p>
<p><strong><a name="Count"></a>Count:</strong> Specify the word Count followed immediately by the total number of rows that the ListView will ultimately contain. This is not a limit: rows beyond the count can still be added. Instead, this option serves as a hint to the control that allows it to allocate memory only once rather than each time a row is added, which greatly improves row-adding performance (it may also improve sorting performance). To improve performance even more, use <code>GuiControl, -Redraw, MyListView</code> prior to adding a large number of rows. Afterward, use <code>GuiControl, +Redraw, MyListView</code> to re-enable redrawing (which also repaints the control).</p>
<p><strong>Grid:</strong> Provides horizontal and vertical lines to visually indicate the boundaries between rows and columns.</p>
<p><strong>Hdr:</strong> Specify <code>-Hdr</code> (minus Hdr) to omit the special top row that contains column titles. To make it visible later, use <code>GuiControl, +Hdr, MyListView</code>.</p>
<p><strong>LV:</strong> Specify the string LV followed immediately by the number of an <a href="../misc/Styles.htm#ListView">extended ListView style</a>. These styles are entirely separate from generic extended styles. For example, specifying <code><strong>-E</strong>0x200</code> would remove the generic extended style WS_EX_CLIENTEDGE to eliminate the control's default border. By contrast, specifying <code><strong>-LV</strong>0x20</code> would remove <a href="#frs">LVS_EX_FULLROWSELECT</a>.</p>
<p><strong>LV0x10</strong>: Specify <code>-LV0x10</code> to prevent the user from dragging column headers to the left or right to reorder them. However, it is usually not necessary to do this because the physical reordering of columns does not affect the column order seen by the script. For example, the first column will always be column 1 from the script's point of view, even if the user has physically moved it to the right of other columns.</p>
<p><strong><a name="frs"></a>LV0x20</strong>: Specify <code>-LV0x20</code> to require that a row be clicked at its first field to select it (normally, a click on <em>any</em> field will select it). The advantage of this is that it makes it easier for the user to drag a rectangle around a group of rows to select them.</p>
<p><strong>Multi:</strong> Specify <code>-Multi</code> (minus Multi) to prevent the user from selecting more than one row at a time.</p>
<p><strong>NoSortHdr:</strong> Prevents the header from being clickable. It will take on a flat appearance rather than its normal button-like appearance. Unlike most other ListView styles, this one cannot be changed after the ListView is created.</p>
<p><strong><a name="NoSort"></a>NoSort:</strong> Turns off the automatic sorting that occurs when the user clicks a column header. However, the header will still behave visually like a button (unless NoSortHdr has been specified). In addition, the g-label will still receive the <a href="#ColClick">ColClick notification</a>, to which it can respond with a custom sort or other action.</p>
<p><strong><a name="ReadOnly"></a>ReadOnly:</strong>  Specify <code>-ReadOnly</code> (minus ReadOnly) to allow editing of the text in the first column of each row. To edit a row, select it then press the <a href="#WantF2">F2 key</a>. Alternatively, you can click a row once to select it, wait at least half a second, then click the same row again to edit it.</p>
<p><strong>R</strong>: Rows of height (upon creation). Specify the letter R followed immediately by the number of rows for which to make room inside the control. For example, <code>R10</code> would make the control 10 rows tall. If the ListView is created with a <a href="#View">view mode</a> other than report view, the control is sized to fit rows of icons instead of rows of text. Note: adding <a href="#IL">icons</a> to a ListView's rows will increase the height of each row, which will make this option inaccurate.</p>
<p><strong><a name="Sort"></a>Sort:</strong> The control is kept alphabetically sorted according to the contents of the first column.</p>
<p><strong><a name="SortDesc" id="SortDesc"></a>SortDesc:</strong> Same as above except in descending order.</p>
<p><strong><a name="WantF2"></a>WantF2</strong> <span class="ver">[v1.0.44+]:</span> Specify <code>-WantF2</code> (minus WantF2) to prevent an F2 keystroke from <a href="#ReadOnly">editing</a> the currently focused row. This setting is ignored unless <code><a href="#ReadOnly">-ReadOnly</a></code> is also in effect. Regardless of this setting, the g-label still receives F2 <a href="#NotifyK">notifications</a>.</p>
<p><strong>(Unnamed numeric styles):</strong> Since styles other than the above are rarely used, they do not have names. See the <a href="../misc/Styles.htm#ListView">ListView styles table</a> for a list.</p>
<h2 id="View">View Modes</h2>
<p>A ListView has five viewing modes, of which the most common is report view (which is the default). To use one of the other views, specify its name in the options list. The view can also be changed after the control is created; for example: <code>GuiControl, +IconSmall, MyListView</code>.</p>
<p><strong>Icon:</strong> Shows a large-icon view. In this view and all the others except <em>Report</em>, the text in columns other than the first is not visible. To display icons in this mode, the ListView must have a large-icon <a href="#IL">ImageList</a> assigned to it.</p>
<p><strong>Tile</strong>: Shows a large-icon view but with ergonomic differences such as displaying each item's text to the right of the icon rather than underneath it. <a href="#Checked">Checkboxes</a> do not function in this view. Also, attempting to show this view on operating systems older than Windows XP has no effect.</p>
<p><strong>IconSmall:</strong> Shows a small-icon view.</p>
<p><strong>List:</strong> Shows a small-icon view in list format, which displays the icons in columns. The number of columns depends on the width of the control and the width of the widest text item in it.</p>
<p><strong>Report:</strong> Switches back to report view, which is the initial default. For example: <code>GuiControl, +Report, MyListView</code>.</p>
<h2 id="BuiltIn">Built-in Functions for ListViews</h2>
<p>All of the ListView functions operate upon the current thread's <a href="Gui.htm#DefaultWin">default GUI window</a> (which can be changed via <a href="Gui.htm#Default"><code>Gui, 2:Default</code></a>). If the default window does not exist or has no ListView controls, all functions return zero to indicate the problem.</p>
<p><a name="GuiLV"></a>If the window has more than one ListView control, by default the functions operate upon the one most recently added. To change this, specify <code>Gui, ListView, ListViewName</code>, where <em>ListViewName</em> is the name of the ListView's <a href="Gui.htm#var">associated variable</a>, its ClassNN as shown by Window Spy or (in v1.1.04+) its HWND. Once changed, all existing and future <a href="../misc/Threads.htm">threads</a> will use the indicated ListView.</p>
<p><a name="RowNumber"></a>When the phrase &quot;row number&quot; is used on this page, it refers to a row's current position within the ListView. The top row is 1, the second row is 2, and so on. After a row is added, its row number tends to change due to sorting, deleting, and inserting of other rows. Therefore, to locate specific row(s) based on their contents, it is usually best to use <a href="#LV_GetText">LV_GetText()</a> in a loop.</p>
<h2 id="bifRow">Row Functions</h2>
<h3><a name="LV_Add"></a>LV_Add([Options, Field1, Field2, ...])</h3>
<p>Adds a new row to the bottom of the list. The parameters <em>Field1</em> and beyond are the columns of the new row, which can be text or numeric (including numeric <a href="../Variables.htm#Expressions">expression</a> results). To make any field blank, specify &quot;&quot; or the equivalent. If there are too few fields to fill all the columns, the columns at the end are left blank. If there are too many fields, the fields at the end are completely ignored.</p>
<p>Upon failure, LV_Add() returns 0. Upon success, it returns the new <a href="#RowNumber">row number</a>, which is not necessarily the last row if the ListView has the <a href="#Sort">Sort</a> or <a href="#SortDesc">SortDesc</a> style.</p>
<h4><a name="RowOptions"></a>Row Options</h4>
<p>The <em>Options</em> parameter is a string containing zero or more words from the list below (not case sensitive). Separate each word from the next with a space or tab. To remove an option, precede it with a minus sign. To add an option, a plus sign is permitted but not required.</p>
<p><strong>Check</strong>: Shows a checkmark in the row (if the ListView has <a href="#Checked">checkboxes</a>). To later uncheck it, use <code>LV_Modify(RowNumber, &quot;-Check&quot;)</code>.</p>
<p><a name="ColN"></a><strong>Col</strong>: Specify the word Col followed immediately by the column number at which to begin applying the parameters <em>Col1</em> and beyond. This is most commonly used with <a href="#LV_Modify">LV_Modify()</a> to alter individual fields in a row without affecting those that lie to their left.</p>
<p><a name="Focus"></a><strong>Focus</strong>: Sets keyboard focus to the row (often used in conjunction with Select). To later de-focus it, use <code>LV_Modify(RowNumber, &quot;-Focus&quot;)</code>.</p>
<p><strong>Icon</strong>: Specify the word Icon followed immediately by the number of this row's icon, which is displayed in the left side of the first column. If this option is absent, the first icon in the <a href="#IL">ImageList</a> is used. To display a blank icon, specify a number that is larger than the number of icons in the ImageList. If the control lacks a small-icon ImageList, no icon is displayed nor is any space reserved for one in <a href="#View">report view</a>.</p>
<p><strong>Select</strong>: Selects the row. To later deselect it, use <code>LV_Modify(RowNumber, &quot;-Select&quot;)</code>. When selecting rows, it is usually best to ensure that at least one row always has the <a href="#Focus">focus property</a> because that allows the Apps key to display its <a href="Gui.htm#GuiContextMenu">context menu</a> (if any) near the focused row. The word <em>Select</em> may optionally be followed immediately by a 0 or 1 to indicate the starting state. In other words, both <code>&quot;Select&quot;</code> and <code>&quot;Select&quot; <strong>.</strong> VarContainingOne</code> are the same (the period used here is the <a href="../Variables.htm#concat">concatenation operator</a>). This technique also works with <em>Focus</em> and <em>Check</em> above.</p>
<p><strong><a name="Vis"></a>Vis</strong> <span class="ver">[v1.0.44+]</span>: Ensures that the specified row is completely visible by scrolling the ListView, if necessary. This has an effect only for LV_Modify(); for example: <code>LV_Modify(RowNumber, &quot;Vis&quot;)</code>.</p>
<h3><a name="LV_Insert"></a>LV_Insert(RowNumber [, Options, Col1, Col2, ...])</h3>
<p>Behaves identically to LV_Add() except for its different first parameter, which specifies the row number for the newly inserted row. Any rows at or beneath <em>RowNumber</em> are shifted downward to make room for the new row. If <em>RowNumber</em> is greater than the number of rows in the list (even as high as 2147483647), the new row is added to the end of the list. For <em>Options</em>, see <a href="#RowOptions">row options</a>.</p>
<h3><a name="LV_Modify"></a>LV_Modify(RowNumber, Options [, NewCol1, NewCol2, ...])</h3>
<p>Modifies the attributes and/or text of a row, and returns 1 upon success and 0 upon failure. If <em>RowNumber</em> is 0, <u>all</u> rows in the control are modified (in this case the function returns 1 on complete success and 0 if any part of the operation failed). When only the first two parameters are present, only the row's attributes and not its text are changed. Similarly, if there are too few parameters to cover all the columns, the columns at the end are not changed. The <a href="#ColN">ColN option</a> may be used to update specific columns without affecting the others. For other options, see <a href="#RowOptions">row options</a>.</p>
<h3><a name="LV_Delete"></a>LV_Delete([RowNumber])</h3>
<p>If the parameter is omitted, <strong>all</strong> rows in the ListView are deleted. Otherwise, only the specified <em>RowNumber</em> is deleted. It returns 1 upon success and 0 upon failure.</p>
<h2 id="bifCol">Column Functions</h2>
<h3><a name="LV_ModifyCol"></a>LV_ModifyCol([ColumnNumber, Options, ColumnTitle])</h3>
<p>Modifies the attributes and/or text of the specified column and its header.  The first column is number 1 (not 0). If all parameters are omitted, the width of every column is adjusted to fit the contents of the rows. If only the first parameter is present, only the specified column is auto-sized. Auto-sizing has no effect when not in Report (Details) view. This function returns 1 upon success and 0 upon failure.</p>
<h4><a name="ColOptions"></a>Column Options</h4>
<p>The <em>Options</em> parameter is a string containing zero or more words from the list below (not case sensitive). Separate each word from the next with a space or tab. To remove an option, precede it with a minus sign. To add an option, a plus sign is permitted but not required.</p>
<h4>Column Options: General</h4>
<p><strong>N</strong>: Specify for N the new width of the column, in pixels. This number can be unquoted if is the only option. For example, the following are both valid: <code>LV_ModifyCol(1, 50)</code> and <code>LV_ModifyCol(1, &quot;50 Integer&quot;)</code>.</p>
<p><strong>Auto</strong>: Adjusts the column's width to fit its contents. This has no effect when not in Report (Details) view.</p>
<p><strong>AutoHdr</strong>: Adjusts the column's width to fit its contents and the column's header text, whichever is wider. If applied to the last column, it will be made at least as wide as all the remaining space in the ListView. It is usually best to apply this setting only after the rows have been added because that allows any newly-arrived vertical scroll bar to be taken into account when sizing the last column. This option has no effect when not in Report (Details) view.</p>
<p><strong>Icon</strong>: Specify the word Icon followed immediately by the number of the <a href="#IL">ImageList's</a> icon to display next to the column header's text. Specify <code>-Icon</code> (minus icon) to remove any existing icon.</p>
<p><strong>IconRight</strong>: Puts the icon on the right side of the column rather than the left.</p>
<h4>Column Options: Data Type</h4>
<p><strong>Float</strong>: For sorting purposes, indicates that this column contains floating point numbers (hexadecimal format is not supported). Sorting performance for Float and Text columns is up to 25 times slower than it is for integers.</p>
<p><a name="Integer"></a><strong>Integer</strong>: For sorting purposes, indicates that this column contains integers. To be sorted properly, each integer must be 32-bit; that is, within the range -2147483648 to 2147483647. If any of the values are not integers, they will be considered zero when sorting (unless they start with a number, in which case that number is used). Numbers may appear in either decimal or hexadecimal format (e.g. <code>0xF9E0</code>).</p>
<p><a name="Text"></a><strong>Text</strong>: Changes the column back to text-mode sorting, which is the initial default for every column. Only the first 8190 characters of text are significant for sorting purposes (except for the <a href="#Logical"><em>Logical</em> option</a>, in which case the limit is 4094).</p>
<h4>Column Options: Alignment / Justification</h4>
<p><strong>Center</strong>: Centers the text in the column. To center an Integer or Float column, specify the word Center after the word Integer or Float.</p>
<p><strong>Left</strong>: Left-justifies the column's text, which is the initial default for every column. On older operating systems, the first column might have a forced left-justification.</p>
<p><strong>Right</strong>: Right-justifies the column's text. This attribute need not be specified for Integer and Float columns because they are right-justified by default. That default can be overridden by specifying something such as <code>&quot;Integer Left&quot;</code> or <code>&quot;Float Center&quot;</code>.</p>
<h4>Column Options: Sorting</h4>
<p><strong><a name="Case" id="Case"></a>Case</strong>: The sorting of the column is case sensitive (affects only <a href="#Text">text</a> columns). If the options <em>Case</em>, <em>CaseLocale</em>, and <em>Logical</em> are all omitted, the uppercase letters A-Z are considered identical to their lowercase counterparts for the purpose of the sort.</p>
<p><strong>CaseLocale</strong> <span class="ver">[v1.0.43.03+]:</span> The sorting of the column is case insensitive based on the current user's locale (affects only <a href="#Text">text</a> columns). For example, most English and Western European locales treat the letters A-Z and ANSI letters like &Auml; and &Uuml; as identical to their lowercase counterparts. This method also uses a &quot;word sort&quot;, which treats hyphens and apostrophes in such a way that words like &quot;coop&quot; and &quot;co-op&quot; stay together.</p>
<p><a name="Desc"></a><strong>Desc</strong>: Descending order. The column starts off in descending order the first time the user sorts it.</p>
<p><a name="Logical"></a><strong>Logical</strong> <span class="ver">[v1.0.44.12+]:</span> Same as <em>CaseLocale</em> except that any sequences of digits in the text are treated as true numbers rather than mere characters. For example, the string &quot;T33&quot; would be considered greater than &quot;T4&quot;. <em>Logical</em> requires Windows XP or later (on older OSes, <em>CaseLocale</em> is automatically used instead). In addition, <em>Logical</em> and <em>Case</em> are currently mutually exclusive: only the one most recently specified will be in effect.</p>
<p><strong>NoSort</strong>: Prevents a user's click on this column from having any automatic sorting effect. To disable sorting for all columns rather than only a subset, include <a href="#NoSort">NoSort</a> in the ListView's options. If the ListView has a g-label, the <a href="#ColClick">ColClick notification</a> will still be received when the user clicks a no-sort column.</p>
<p><strong>Sort</strong>: Immediately sorts the column in ascending order (even if it has the <a href="#Desc">Desc</a> option).</p>
<p><strong>SortDesc</strong>: Immediately sorts the column in descending order.</p>
<p><strong>Uni</strong>: Unidirectional sort. This prevents a second click on the same column from reversing the sort direction.</p>
<h3><a name="LV_InsertCol"></a>LV_InsertCol(ColumnNumber [, Options, ColumnTitle])</h3>
<p>Creates a new column, inserting it as the specified <em>ColumnNumber</em> (shifting any other columns to the right to make room). The first column is 1 (not 0). If <em>ColumnNumber</em> is larger than the number of columns currently in the control, the new column is added to the end of the list. The newly inserted column starts off with empty contents beneath it unless it is the first column, in which case it inherits the old first column's contents and the old first column acquires blank contents. The new column's attributes -- such as whether or not it uses <a href="#Integer">integer sorting</a> -- always start off at their defaults unless changed via <em><a href="#ColOptions">Options</a></em>. This function returns the new column's position number (or 0 upon failure). The maximum number of columns in a ListView is 200.</p>
<h3><a name="LV_DeleteCol"></a>LV_DeleteCol(ColumnNumber)</h3>
<p>Deletes the specified column and all of the contents beneath it. It returns 1 upon success and 0 upon failure. Once a column is deleted, the column numbers of any that lie to its right are reduced by 1. Consequently, calling <code>LV_DeleteCol(2)</code> twice would delete the second and third columns. On operating systems older than Windows XP, attempting to delete the original first column might fail and return 0.</p>
<h2 id="bifGet">Getting Data Out of a ListView</h2>
<h3><a name="LV_GetCount"></a>LV_GetCount([&quot;Selected | Column&quot;])</h3>
<p>When the parameter is omitted, the function returns the total number of rows in the control. When the parameter is &quot;S&quot; or &quot;Selected&quot;, the count includes only the selected/highlighted rows. When the parameter is &quot;Col&quot; or &quot;Column&quot;, the function returns the number of columns in the control. This function is always instantaneous because the control keeps track of these counts.</p>
<p>This function is often used in the top line of a Loop, in which case the function would get called only once (prior to the first iteration). For example:</p>
<pre>Loop % LV_GetCount()
{
    LV_GetText(RetrievedText, A_Index)
    if InStr(RetrievedText, &quot;some filter text&quot;)
        LV_Modify(A_Index, &quot;Select&quot;)  <em>; Select each row whose first field contains the filter-text.</em>
}</pre>
<p>To retrieve the widths of a ListView's columns -- for uses such as saving them to an INI file to be remembered between sessions -- follow this example:</p>
<pre>Gui +LastFound
Loop % LV_GetCount(&quot;Column&quot;)
{
    SendMessage, 4125, A_Index - 1, 0, SysListView321  <em>; 4125 is LVM_GETCOLUMNWIDTH.</em>
    MsgBox Column %A_Index%'s width is %ErrorLevel%.
}</pre>
<h3><a name="LV_GetNext"></a>LV_GetNext([StartingRowNumber, &quot;Checked | Focused&quot;])</h3>
<p>Returns the row number of the next selected, checked, or focused row. If none is found, zero is returned. If <em>StartingRowNumber</em> is omitted or less than 1, the search begins at the top of the list. Otherwise, the search begins at the row after <em>StartingRowNumber</em>. If the second parameter is omitted, the function searches for the next selected/highlighted row. Otherwise, specify &quot;C&quot; or &quot;Checked&quot; to find the next checked row; or &quot;F&quot; or &quot;Focused&quot; to find the focused row (there is never more than one focused row in the entire list, and sometimes there is none at all). The following example reports all selected rows in the ListView:</p>
<pre>RowNumber = 0  <em>; This causes the first loop iteration to start the search at the top of the list.</em>
Loop
{
    RowNumber := LV_GetNext(RowNumber)  <em>; Resume the search at the row after that found by the previous iteration.</em>
    if not RowNumber  <em>; The above returned zero, so there are no more selected rows.</em>
        break
    LV_GetText(Text, RowNumber)
    MsgBox The next selected row is #%RowNumber%, whose first field is &quot;%Text%&quot;.
}</pre>
<p>An alternate method to find out if a particular row number is checked is the following:</p>
<pre>Gui +LastFound
SendMessage, 4140, <i>RowNumber</i> - 1, 0xF000, SysListView321  <em>; 4140 is LVM_GETITEMSTATE.  0xF000 is LVIS_STATEIMAGEMASK.</em>
IsChecked := (ErrorLevel &gt;&gt; 12) - 1  <em>; This sets IsChecked to true if <i>RowNumber</i> is checked or false otherwise.</em></pre>
<h3><a name="LV_GetText"></a>LV_GetText(OutputVar, RowNumber [, ColumnNumber])</h3>
<p>Retrieves the text at the specified <em>RowNumber</em> and <em>ColumnNumber</em> and stores it in <em>OutputVar</em>.  If <em>ColumnNumber</em> is omitted, it defaults to 1 (the text in the first column). If <em>RowNumber</em> is 0, the column header text is retrieved. If the text is longer than 8191, only the first 8191 characters are retrieved. The function returns 1 upon success and 0 upon failure. Upon failure, <em>OutputVar</em> is also made blank.</p>
<p>Column numbers seen by the script are not altered by any dragging and dropping of columns the user may have done. For example, the original first column is still number 1 even if the user drags it to the right of other columns.</p>
<h2 id="notify">G-Label Notifications (Primary)</h2>
<p>A <a href="Gui.htm#label">g-label</a> such as <code><strong>g</strong>MySubroutine</code> may be listed in the control's options. This would cause the <em>MySubroutine</em> label to be launched automatically whenever the user performs an action in the control. This subroutine may consult the built-in variables <a href="../Variables.htm#Gui">A_Gui</a> and <a href="../Variables.htm#GuiControl">A_GuiControl</a> to find out which window and ListView generated the event. More importantly, it may consult <strong>A_GuiEvent</strong>, which contains one of the following strings or letters (for compatibility with future versions, a script should not assume these are the only possible values):</p>
<p><strong>DoubleClick</strong>: The user has double-clicked within the control. The variable A_EventInfo contains the focused row number. <a href="#LV_GetNext">LV_GetNext()</a> can be used to instead get the first <em>selected</em> row number, which is 0 if the user double-clicked on empty space.</p>
<p><strong>R</strong>: The user has <em>double-right</em>-clicked within the control. The variable A_EventInfo contains the focused row number.</p>
<p><strong><a name="ColClick"></a>ColClick</strong>: The user has clicked a column header. The variable A_EventInfo contains the column number, which is the original number assigned when the column was created; that is, it does not reflect any dragging and dropping of columns done by the user. One possible response to a column click is to sort by a hidden column (zero width) that contains data in a sort-friendly format (such as a YYYYMMDD integer date). Such a hidden column can mirror some other column that displays the same data in a more friendly format (such as MM/DD/YY). For example, a script could hide column 3 via <code><a href="#LV_ModifyCol">LV_ModifyCol(3, 0)</a></code>, then disable automatic sorting in the visible column 2 via <code>LV_ModifyCol(2, &quot;NoSort&quot;)</code>. Then in response to the ColClick notification for column 2, the script would sort the ListView by the hidden column via <code>LV_ModifyCol(3, &quot;Sort&quot;)</code>.</p>
<p><strong><a name="Drag" id="Drag"></a>D</strong>: The user has attempted to start dragging a row or icon (there is currently no built-in support for dragging rows or icons). The variable A_EventInfo contains the focused row number. In v1.0.44+, this notification occurs even without <a href="#AltSubmit">AltSubmit</a>.</p>
<p><strong>d</strong> (lowercase D): Same as above except a right-click-drag rather than a left-drag.</p>
<p><strong>e</strong> (lowercase E): The user has finished editing the first field of a row (the user may edit it only when the ListView has <code><a href="#ReadOnly"><strong>-</strong>ReadOnly</a></code> in its options). The variable A_EventInfo contains the row number.</p>
<h2>G-Label Notifications (Secondary)</h2>
<p>If the ListView has the word AltSubmit in its <a href="#Options">options</a>, its g-label is launched more often and <strong>A_GuiEvent</strong> may contain the following additional values:</p>
<p><strong>Normal</strong>: The user has left-clicked a row. The variable A_EventInfo contains the focused row number.</p>
<p><strong>RightClick</strong>: The user has right-clicked a row. The variable A_EventInfo contains the focused row number. In most cases, it is best not to display a menu in response to this. Instead, use the <a href="Gui.htm#GuiContextMenu">GuiContextMenu label</a> because it also recognizes the Apps key. For example:</p>
<pre>GuiContextMenu:  <em>; Launched in response to a right-click or press of the Apps key.</em>
if A_GuiControl &lt;&gt; MyListView  <em>; This check is optional. It displays the menu only for clicks inside the ListView.</em>
    return
<em>; Show the menu at the provided coordinates, A_GuiX and A_GuiY.  These should be used
; because they provide correct coordinates even if the user pressed the Apps key:</em>
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return</pre>
<p><strong>A</strong>: A row has been activated, which by default occurs when it is double clicked. The variable A_EventInfo contains the row number.</p>
<p><strong>C</strong>: The ListView has released mouse capture.</p>
<p><strong>E</strong>: The user has begun editing the first field of a row (the user may edit it only when the ListView has <code><a href="#ReadOnly">-ReadOnly</a></code> in its options). The variable A_EventInfo contains the row number.</p>
<p><strong>F</strong>: The ListView has received keyboard focus.</p>
<p><strong>f</strong> (lowercase F): The ListView has lost keyboard focus.</p>
<p><strong><a name="ItemChanged"></a>I</strong>: Item changed. A row has changed by becoming selected/deselected, checked/unchecked, etc. If the user selects a new row, at least two such notifications are received: one for the de-selection of the previous row, and one for the selection of the new row. In v1.0.44+, the variable A_EventInfo contains the row number. In v1.0.46.10+, ErrorLevel contains zero or more of the following letters to indicate how the item changed: S (select) or s (de-select), and/or F (focus) or f (de-focus), and/or C (checkmark) or c (uncheckmark). For example, SF means that the row has been selected and focused. To detect whether a particular letter is present, use a <a href="LoopParse.htm">parsing loop</a> or the case-sensitive option of <a href="../Functions.htm#InStr">InStr()</a>; for example: <code>InStr(ErrorLevel, &quot;S&quot;, true)</code>. Note: For compatibility with future versions, a script should not assume that &quot;SsFfCc&quot; are the only possible letters. Also, specifying <a href="Critical.htm">Critical</a> as the <a href="Gui.htm#label">g-label</a>'s first line ensures that all &quot;I&quot; notifications are received (otherwise, some might be lost if the script cannot keep up with them).</p>
<p><strong><a name="NotifyK"></a>K</strong>: The user has pressed a key while the ListView has focus. A_EventInfo contains the virtual key code of the key, which is a number between 1 and 255. This can be translated to a key name or character via <a href="../Functions.htm#GetKeyName">GetKeyName</a>. For example, <code>key := GetKeyName(<a href="Format.htm">Format</a>("vk{:x}", A_EventInfo))</code>. On most keyboard layouts, keys A-Z can be translated to the corresponding character via <code><a href="../Functions.htm#Chr">Chr(A_EventInfo)</a></code>. F2 keystrokes are received regardless of <a href="#WantF2">WantF2</a>. However, the Enter keystroke is not received; to receive it, use a default button as described <a href="#Enter">below</a>.</p>
<p><strong>M</strong>: Marquee. The user has started to drag a selection-rectangle around a group of rows or icons.</p>
<p><strong>S</strong>: The user has begun scrolling the ListView.</p>
<p><strong>s</strong> (lowercase S): The user has finished scrolling the ListView.</p>
<h2 id="IL">ImageList <span class="ver">(the means by which icons are added to a ListView)</span></h2>
<p>An Image-List is a group of identically sized icons stored in memory. Upon creation, each ImageList is empty. The script calls IL_Add() repeatedly to add icons to the list, and each icon is assigned a sequential number starting at 1. This is the number to which the script refers to display a particular icon in a row or column header. Here is a working example that demonstrates how to put icons into a ListView's rows:</p>
<pre>Gui, Add, ListView, h200 w180, Icon &amp; Number|Description  <em>; Create a ListView.</em>
ImageListID := <a href="#IL_Create">IL_Create</a>(10)  <em>; Create an ImageList to hold 10 small icons.</em>
<a href="#LV_SetImageList">LV_SetImageList</a>(ImageListID)  <em>; Assign the above ImageList to the current ListView.</em>
Loop 10  <em>; Load the ImageList with a series of icons from the DLL.</em>
    <a href="#IL_Add">IL_Add</a>(ImageListID, &quot;shell32.dll&quot;, A_Index) 
Loop 10  <em>; Add rows to the ListView (for demonstration purposes, one for each icon).</em>
    LV_Add(&quot;Icon&quot; . A_Index, A_Index, &quot;n/a&quot;)
LV_ModifyCol(&quot;Hdr&quot;)  <em>; Auto-adjust the column widths.</em>
Gui Show
return

GuiClose:  <em>; Exit the script when the user closes the ListView's GUI window.</em>
ExitApp</pre>
<h3><a name="IL_Create"></a>IL_Create([InitialCount, GrowCount, LargeIcons?])</h3>
<p>Creates a new ImageList, initially empty, and returns the unique ID of the ImageList (or 0 upon failure). <em>InitialCount</em> is the number of icons you expect to put into the list immediately (if omitted, it defaults to 2). <em>GrowCount</em> is the number of icons by which the list will grow each time it exceeds the current list capacity (if omitted, it defaults to 5). <em>LargeIcons</em> should be a numeric value: If non-zero, the ImageList will contain large icons. If zero, it will contain small icons (this is the default when omitted). Icons added to the list are scaled automatically to conform to the system's dimensions for small and large icons.</p>
<h3><a name="LV_SetImageList"></a>LV_SetImageList(ImageListID [, 0|1|2])</h3>
<p>This function is normally called prior to adding any rows to the ListView. It sets the <a href="#IL">ImageList</a> whose icons will be displayed by the ListView's rows (and optionally, its columns). ImageListID is the number returned from a previous call to <a href="#IL_Create">IL_Create()</a>. If the second parameter is omitted, the type of icons in the ImageList is detected automatically as large or small. Otherwise, specify 0 for large icons, 1 for small icons, and 2 for state icons (state icons are not yet directly supported, but they could be used via <a href="PostMessage.htm">SendMessage</a>).</p>
<p>A ListView may have up to two ImageLists: small-icon and/or large-icon. This is useful when the script allows the user to switch to and from the large-icon view. To add more than one ImageList to a ListView, call LV_SetImageList() a second time, specifying the ImageListID of the second list. A ListView with both a large-icon and small-icon ImageList should ensure that both lists contain the icons in the same order. This is because the same ID number is used to reference both the large and small versions of a particular icon.</p>
<p>Although it is traditional for all <a href="#View">viewing modes</a> except Icon and Tile to show small icons, this can be overridden by passing a large-icon list to LV_SetImageList and specifying 1 (small-icon) for the second parameter. This also increases the height of each row in the ListView to fit the large icon.</p>
<p>If successful, LV_SetImageList() returns the ImageListID that was previously associated with the ListView (or 0 if none). Any such detached ImageList should normally be destroyed via <a href="#IL_Destroy">IL_Destroy(ImageListID)</a>.</p>
<h3><a name="IL_Add"></a>IL_Add(ImageListID, Filename [, IconNumber, ResizeNonIcon?])</h3>
<p>Adds an icon or picture to the specified <em>ImageListID</em> and returns the new icon's index (1 is the first icon, 2 is the second, and so on). <em>Filename</em> is the name of an icon (.ICO), cursor (.CUR), or animated cursor (.ANI) file (animated cursors will not actually be animated when displayed in a ListView). Other sources of icons include the following types of files: EXE, DLL, CPL, SCR, and other types that contain icon resources. To use an icon group other than the first one in the file, specify its number for <em>IconNumber</em>. If <em>IconNumber</em> is negative, its absolute value is assumed to be the resource ID of an icon within an executable file. In the following example, the default icon from the second icon group would be used: <code>IL_Add(ImageListID, &quot;C:\My Application.exe&quot;, 2)</code>.</p>
<p>Non-icon images such as BMP, GIF and JPG may also be loaded. However, in this case the last two parameters should be specified to ensure correct behavior: <em>IconNumber</em> should be the mask/transparency color number (0xFFFFFF [the color white] might be best for most pictures); and <em>ResizeNonIcon</em> should be non-zero to cause the picture to be scaled to become a single icon, or zero to divide up the image into however many icons can fit into its actual width.</p>
<p>All operating systems support GIF, JPG, BMP, ICO, CUR, and ANI images. On Windows XP or later, additional image formats such as PNG, TIF, Exif, WMF, and EMF are supported. Operating systems older than XP can be given support by copying Microsoft's free GDI+ DLL into the AutoHotkey.exe folder (but in the case of a <a href="../Scripts.htm#ahk2exe">compiled script</a>, copy the DLL into the script's folder). To download the DLL, search for the following phrase at <a href="http://www.microsoft.com">www.microsoft.com</a>: gdi redistributable</p>
<h3><a name="IL_Destroy"></a>IL_Destroy(ImageListID)</h3>
<p>Deletes the specified ImageList and returns 1 upon success and 0 upon failure. It is normally not necessary to destroy ImageLists because once attached to a ListView, they are destroyed automatically when the ListView or its parent window is destroyed. However, if the ListView shares ImageLists with other ListViews (by having <code>0x40</code> in its options), the script should explicitly destroy the ImageList after destroying all the ListViews that use it. Similarly, if the script replaces one of a ListView's old ImageLists with a new one, it should explicitly destroy the old one.</p>
<h2 id="Remarks">ListView Remarks</h2>
<p>The <a href="Gui.htm#Submit">Gui Submit</a> command has no effect on a ListView control. Therefore, the script may use the ListView's <a href="Gui.htm#var">associated variable</a> (if any) to store other data without concern that it will ever be overwritten.</p>
<p>After a column is sorted -- either by means of the user clicking its header or the script calling <code><a href="#LV_ModifyCol">LV_ModifyCol(1, &quot;Sort&quot;)</a></code> -- any subsequently added rows will appear at the bottom of the list rather than obeying the sort order. The exception to this is the <a href="#Sort">Sort</a> and <a href="#SortDesc">SortDesc</a> styles, which move newly added rows into the correct positions.</p>
<p><a name="Enter"></a>To detect when the user has pressed Enter while a ListView has focus, use a <a href="GuiControls.htm#DefaultButton">default button</a> (which can be hidden if desired). For example:</p>
<pre>Gui, Add, Button, Hidden Default, OK
...
ButtonOK:
GuiControlGet, FocusedControl, FocusV
if FocusedControl &lt;&gt; MyListView
    return
MsgBox % &quot;Enter was pressed. The focused row number is &quot; . LV_GetNext(0, &quot;Focused&quot;)
return</pre>
<p>In addition to navigating from row to row with the keyboard, the user may also perform incremental search by typing the first few characters of an item in the first column. This causes the selection to jump to the nearest matching row.</p>
<p>Although any length of text can be stored in each field of a ListView, only the first 260 characters are displayed.</p>
<p>Although the maximum number of rows in a ListView is limited only by available system memory, row-adding performance can be greatly improved as described in the <a href="#Count">Count</a> option.</p>
<p>A picture may be used as a background around a ListView (that is, to frame the ListView). To do this, create the <a href="GuiControls.htm#Picture">picture control</a> after the ListView and include <code>0x4000000</code> (which is WS_CLIPSIBLINGS) in the picture's <em>Options</em>.</p>
<p>A script may create more than one ListView per window. To operate upon a ListView other than the default one, see <a href="#BuiltIn">built-in functions</a>.</p>
<p>It is best not to insert or delete columns directly with <a href="PostMessage.htm">SendMessage</a>. This is because the program maintains a collection of <a href="#Integer">sorting preferences</a> for each column, which would then get out of sync. Instead, use the <a href="#bifCol">built-in column functions</a>.</p>
<p>To perform actions such as resizing, hiding, or changing the font of a ListView, use <a href="GuiControl.htm">GuiControl</a>.</p>
<p>To extract text from external ListViews (those not owned by the script), use <a href="ControlGet.htm#List">ControlGet List</a>.</p>
<h2>Related</h2>
<p><a href="TreeView.htm">TreeView</a>, <a href="GuiControls.htm">Other Control Types</a>, <a href="Gui.htm">Gui</a>, <a href="Gui.htm#GuiContextMenu">GuiContextMenu</a>, <a href="GuiControl.htm">GuiControl</a>, <a href="GuiControlGet.htm">GuiControlGet</a>, <a href="../misc/Styles.htm#ListView">ListView styles table</a></p>
<h2 id="Examples">Examples</h2>
<pre class="NoIndent"><em>; Select or de-select all rows by specifying 0 as the row number:</em>
<a href="#LV_Modify">LV_Modify</a>(0, &quot;Select&quot;)   <em>; Select all.</em>
LV_Modify(0, &quot;-Select&quot;)  <em>; De-select all.</em>
LV_Modify(0, &quot;-Check&quot;)  <em>; Uncheck all the <a href="#Checked">checkboxes</a>.</em>

<em>; Auto-size all columns to fit their contents:</em>
<a href="#LV_ModifyCol">LV_ModifyCol</a>()  <em>; There are no parameters in this mode.</em></pre>
<p>&nbsp;</p>
<pre class="NoIndent"><em>; MAIN EXAMPLE
; The following is a working script that is more elaborate than the one near the top of this page.
; It displays the files in a folder chosen by the user, with each file assigned the icon associated with
; its type. The user can double-click a file, or right-click one or more files to display a context menu.</em>

<em>; Allow the user to maximize or drag-resize the window:</em>
Gui +Resize

<em>; Create some buttons:</em>
Gui, Add, Button, Default gButtonLoadFolder, Load a folder
Gui, Add, Button, x+20 gButtonClear, Clear List
Gui, Add, Button, x+20, Switch View

<em>; Create the ListView and its columns:</em>
<a href="#GuiAdd">Gui, Add, ListView</a>, xm r20 w700 vMyListView gMyListView, Name|In Folder|Size (KB)|Type
<a href="#LV_ModifyCol">LV_ModifyCol</a>(3, &quot;Integer&quot;)  <em>; For sorting, indicate that the Size column is an integer.</em>

<em>; Create an ImageList so that the ListView can display some icons:</em>
ImageListID1 := <a href="#IL_Create">IL_Create</a>(10)
ImageListID2 := IL_Create(10, 10, true)  <em>; A list of large icons to go with the small ones.</em>

<em>; Attach the ImageLists to the ListView so that it can later display the icons:</em>
<a href="#LV_SetImageList">LV_SetImageList</a>(ImageListID1)
LV_SetImageList(ImageListID2)

<em>; Create a popup menu to be used as the context menu:</em>
<a href="Menu.htm">Menu</a>, MyContextMenu, Add, Open, ContextOpenFile
Menu, MyContextMenu, Add, Properties, ContextProperties
Menu, MyContextMenu, Add, Clear from ListView, ContextClearRows
Menu, MyContextMenu, Default, Open  <em>; Make &quot;Open&quot; a bold font to indicate that double-click does the same thing.</em>

<em>; Display the window and return. The OS will notify the script whenever the user
; performs an eligible action:</em>
Gui, Show
return


ButtonLoadFolder:
Gui +OwnDialogs  <em>; Forces user to dismiss the following dialog before using main window.</em>
FileSelectFolder, Folder,, 3, Select a folder to read:
if not Folder  <em>; The user canceled the dialog.</em>
    return

<em>; Check if the last character of the folder name is a backslash, which happens for root
; directories such as C:\. If it is, remove it to prevent a double-backslash later on.</em>
StringRight, LastChar, Folder, 1
if LastChar = \
    StringTrimRight, Folder, Folder, 1  <em>; Remove the trailing backslash.</em>

<em>; Calculate buffer size required for SHFILEINFO structure.</em>
sfi_size := A_PtrSize + 8 + (A_IsUnicode ? 680 : 340)
VarSetCapacity(sfi, sfi_size)

<em>; Gather a list of file names from the selected folder and append them to the ListView:</em>
GuiControl, -Redraw, MyListView  <em>; Improve performance by disabling redrawing during load.</em>
Loop %Folder%\*.*
{
    FileName := A_LoopFileFullPath  <em>; Must save it to a writable variable for use below.</em>

    <em>; Build a unique extension ID to avoid characters that are illegal in variable names,</em>
    <em>; such as dashes.  This unique ID method also performs better because finding an item</em>
    <em>; in the array does not require search-loop.</em>
    SplitPath, FileName,,, FileExt  <em>; Get the file's extension.</em>
    if FileExt in EXE,ICO,ANI,CUR
    {
        ExtID := FileExt  <em>; Special ID as a placeholder.</em>
        IconNumber = 0  <em>; Flag it as not found so that these types can each have a unique icon.</em>
    }
    else  <em>; Some other extension/file-type, so calculate its unique ID.</em>
    {
        ExtID = 0  <em>; Initialize to handle extensions that are shorter than others.</em>
        Loop 7     <em>; Limit the extension to 7 characters so that it fits in a 64-bit value.</em>
        {
            StringMid, ExtChar, FileExt, A_Index, 1
            if not ExtChar  <em>; No more characters.</em>
                break
            <em>; Derive a Unique ID by assigning a different bit position to each character:</em>
            ExtID := ExtID | (Asc(ExtChar) &lt;&lt; (8 * (A_Index - 1)))
        }
        <em>; Check if this file extension already has an icon in the ImageLists. If it does,</em>
        <em>; several calls can be avoided and loading performance is greatly improved,</em>
        <em>; especially for a folder containing hundreds of files:</em>
        IconNumber := IconArray%ExtID%
    }
    if not IconNumber  <em>; There is not yet any icon for this extension, so load it.</em>
    {
        <em>; Get the high-quality small-icon associated with this file extension:</em>
        if not DllCall(&quot;Shell32\SHGetFileInfo&quot; . (A_IsUnicode ? &quot;W&quot;:&quot;A&quot;), &quot;str&quot;, FileName
            , &quot;uint&quot;, 0, &quot;ptr&quot;, &amp;sfi, &quot;uint&quot;, sfi_size, &quot;uint&quot;, 0x101)  <em>; 0x101 is SHGFI_ICON+SHGFI_SMALLICON</em>
            IconNumber = 9999999  <em>; Set it out of bounds to display a blank icon.</em>
        else <em>; Icon successfully loaded.</em>
        {
            <em>; Extract the hIcon member from the structure:</em>
            hIcon := NumGet(sfi, 0)
            <em>; Add the HICON directly to the small-icon and large-icon lists.</em>
            <em>; Below uses +1 to convert the returned index from zero-based to one-based:</em>
            IconNumber := DllCall(&quot;ImageList_ReplaceIcon&quot;, &quot;ptr&quot;, ImageListID1, &quot;int&quot;, -1, &quot;ptr&quot;, hIcon) + 1
            DllCall(&quot;ImageList_ReplaceIcon&quot;, &quot;ptr&quot;, ImageListID2, &quot;int&quot;, -1, &quot;ptr&quot;, hIcon)
            <em>; Now that it's been copied into the ImageLists, the original should be destroyed:</em>
            DllCall(&quot;DestroyIcon&quot;, &quot;ptr&quot;, hIcon)
            <em>; Cache the icon to save memory and improve loading performance:</em>
            IconArray%ExtID% := IconNumber
        }
    }

    <em>; Create the new row in the ListView and assign it the icon number determined above:</em>
    <a href="#LV_Add">LV_Add</a>(&quot;Icon&quot; . IconNumber, A_LoopFileName, A_LoopFileDir, A_LoopFileSizeKB, FileExt)
}
GuiControl, +Redraw, MyListView  <em>; Re-enable redrawing (it was disabled above).</em>
LV_ModifyCol()  <em>; Auto-size each column to fit its contents.</em>
LV_ModifyCol(3, 60) <em>; Make the Size column at little wider to reveal its header.</em>
return


ButtonClear:
<a href="#LV_Delete">LV_Delete</a>()  <em>; Clear the ListView, but keep icon cache intact for simplicity.</em>
return

ButtonSwitchView:
if not IconView
    GuiControl, +Icon, MyListView    <em>; Switch to icon view.</em>
else
    GuiControl, +Report, MyListView  <em>; Switch back to details view.</em>
IconView := not IconView             <em>; Invert in preparation for next time.</em>
return

MyListView:
if A_GuiEvent = DoubleClick  <em>; There are many other possible values the script can check.</em>
{
    <a href="#LV_GetText">LV_GetText</a>(FileName, A_EventInfo, 1) <em>; Get the text of the first field.</em>
    LV_GetText(FileDir, A_EventInfo, 2)  <em>; Get the text of the second field.</em>
    Run %FileDir%\%FileName%,, UseErrorLevel
    if ErrorLevel
        MsgBox Could not open &quot;%FileDir%\%FileName%&quot;.
}
return

<a href="Gui.htm#GuiContextMenu">GuiContextMenu</a>:  <em>; Launched in response to a right-click or press of the Apps key.</em>
if A_GuiControl &lt;&gt; MyListView  <em>; Display the menu only for clicks inside the ListView.</em>
    return
<em>; Show the menu at the provided coordinates, A_GuiX and A_GuiY.  These should be used
; because they provide correct coordinates even if the user pressed the Apps key:</em>
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return

ContextOpenFile:  <em>; The user selected &quot;Open&quot; in the context menu.</em>
ContextProperties:  <em>; The user selected &quot;Properties&quot; in the context menu.
; For simplicitly, operate upon only the focused row rather than all selected rows:</em>
FocusedRowNumber := <a href="#LV_GetNext">LV_GetNext</a>(0, &quot;F&quot;)  <em>; Find the focused row.</em>
if not FocusedRowNumber  <em>; No row is focused.</em>
    return
LV_GetText(FileName, FocusedRowNumber, 1) <em>; Get the text of the first field.</em>
LV_GetText(FileDir, FocusedRowNumber, 2)  <em>; Get the text of the second field.</em>
IfInString A_ThisMenuItem, Open  <em>; User selected &quot;Open&quot; from the context menu.</em>
    Run %FileDir%\%FileName%,, UseErrorLevel
else  <em>; User selected &quot;Properties&quot; from the context menu.</em>
    Run Properties &quot;%FileDir%\%FileName%&quot;,, UseErrorLevel
if ErrorLevel
    MsgBox Could not perform requested action on &quot;%FileDir%\%FileName%&quot;.
return

ContextClearRows:  <em>; The user selected &quot;Clear&quot; in the context menu.</em>
RowNumber = 0  <em>; This causes the first iteration to start the search at the top.</em>
Loop
{
    <em>; Since deleting a row reduces the RowNumber of all other rows beneath it,</em>
    <em>; subtract 1 so that the search includes the same row number that was previously</em>
    <em>; found (in case adjacent rows are selected):</em>
    RowNumber := LV_GetNext(RowNumber - 1)
    if not RowNumber  <em>; The above returned zero, so there are no more selected rows.</em>
        break
    LV_Delete(RowNumber)  <em>; Clear the row from the ListView.</em>
}
return

GuiSize:  <em>; Expand or shrink the ListView in response to the user's resizing of the window.</em>
if A_EventInfo = 1  <em>; The window has been minimized.  No action needed.</em>
    return
<em>; Otherwise, the window has been resized or maximized. Resize the ListView to match.</em>
GuiControl, Move, MyListView, % &quot;W&quot; . (A_GuiWidth - 20) . &quot; H&quot; . (A_GuiHeight - 40)
return

GuiClose:  <em>; When the window is closed, exit the script automatically:</em>
ExitApp</pre>

</body>
</html>
